home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Examples / robotStuff / robot3A.wwModel / model.eve
Encoding:
Text File  |  1995-03-22  |  13.7 KB  |  481 lines

  1. #
  2. # all measurements are in feet
  3. #
  4. set pi 3.1415926535897932384626433
  5. proc dToR {degrees} { global pi; return [expr {[expr {$degrees*$pi}]/180.0}]; }
  6. proc rToD {radians} { global pi; return [expr {[expr {$radians*180.0}]/$pi}]; }
  7.  
  8. set nodAngle 0.0
  9. set shakeAngle 0.0
  10.  
  11. set headRadius .25
  12. set headColor {.8 .8 .8}
  13. set kindOfHead plain
  14.  
  15. set initialEyeScale .2
  16. set eyeRadius [expr {$headRadius*$initialEyeScale}]
  17. set eyeProtrusion .85
  18. set initialEyeYaw 20.0
  19. set initialEyePitch 10.0
  20. set eyePitch 0.0
  21. set eyeYaw 0.0
  22. set eyeRoll 0.0
  23. set eyeScale 1.0
  24. set eyeColor {.4 .5 1}
  25.  
  26. set pupilRadius [expr {$eyeRadius*.5}]
  27. set pupilScale 1.0
  28. set pupilColor {0 0 0}
  29.  
  30. set noseLength [expr {$headRadius*.5}]
  31. set noseWidth [expr {$headRadius*.2}]
  32. set noseColor {1 .2 0}
  33.  
  34. set crestCount 11
  35. set crestLength [expr {$headRadius*1.5}]
  36. set crestWidth [expr {$headRadius*.2}]
  37. set crestColor {1 0 0}
  38. set crestYawStep 10.0
  39.  
  40. set antennaColor {1 .9 1}
  41. set antennaTilt 30
  42. set antennaLength  [expr {$headRadius*1.5}]
  43. set antennaRadius  [expr {$headRadius*.1}]
  44. set antennaKnobColor {1 .9 1}
  45. set antennaKnobRadius     [expr {$antennaRadius*2.}]
  46.  
  47.  
  48. # some manipulation notes:
  49. # by adjusting the initialEyePitch, you can move from "predator" to "prey"
  50.  
  51. proc declareShaderAttributes {} {
  52.  
  53.   ### plastic shader stuff
  54.   Declare "Ks" "float"
  55.   Declare "Kd" "float"
  56.   Declare "Ka" "float"
  57.   Declare "roughness" "float"
  58.   Declare "specularcolor" "color"
  59.  
  60.   ### VGBlisteredPaintedMetal shader stuff
  61.   Declare "Name" "string"
  62.   Declare "MetalColor" "color"
  63.   Declare "Age" "float"
  64.   Declare "HeightScale" "float"
  65.   Declare "Ambient" "float"
  66.   Declare "Gloss" "float"
  67.   Declare "Specular" "float"
  68.   Declare "Roughness" "float"
  69.   Declare "Displacement" "string"
  70.   Declare "Origin" "point"
  71.   Declare "UpVector" "point"
  72.   Declare "AtVector" "point"
  73.   Declare "Unit" "string"
  74.   Declare "Scale" "float"
  75.   Declare "AntiAlias" "float"
  76.  
  77. }
  78.  
  79. proc buildSphereHead {{xOrigin 0.0} {yOrigin 0.0} {zOrigin 0.0}} {
  80.   global nodAngle shakeAngle
  81.   global kindOfHead headRadius eyeRadius eyeProtrusion
  82.   global pupilRadius pupilScale 
  83.   global noseLength noseWidth 
  84.   global initialEyeYaw initialEyePitch
  85.   global eyeYaw eyePitch eyeRoll
  86.   global eyeScale
  87.   global headColor eyeColor pupilColor noseColor
  88.   
  89.  
  90.   ##########
  91.   startShape Neck
  92.     ApplyToCTM {Translate $xOrigin $yOrigin $zOrigin}
  93.     ApplyToCTM {Rotate 90 1 0 0}
  94.     Cylinder [expr {$headRadius/3.0}] 0  [expr {2*$headRadius}] 360 
  95.   endShape
  96.  
  97.  
  98.   startShape Head 
  99.     ApplyToCTM {Translate $xOrigin $yOrigin $zOrigin}
  100.     EveCmd {Color $headColor}
  101.     EveCmd {Rotate $nodAngle 1 0 0 }
  102.     EveCmd {Rotate $shakeAngle 0 1 0 }
  103.     Sphere $headRadius [expr {-$headRadius}] $headRadius 360 
  104.  
  105.     ##########
  106.     startShape LeftEye
  107.       Surface plastic
  108.       EveCmd {Rotate $initialEyeYaw 1 0 0}
  109.       EveCmd {Rotate $initialEyePitch 0 1 0}
  110.       EveCmd {Translate 0 \
  111.                         [expr {$headRadius*sin([dToR $initialEyeYaw])}] \
  112.                         [expr {-$eyeProtrusion*$headRadius*cos([dToR $initialEyeYaw])}]}
  113.       ##########
  114.       startShape EyeBall
  115.         EveCmd {Scale $eyeScale $eyeScale $eyeScale}
  116.         EveCmd {Rotate $eyeYaw 1 0 0}
  117.         EveCmd {Rotate $eyePitch 0 1 0}
  118.         EveCmd {Rotate $eyeRoll 0 0 1}
  119.         EveCmd {Color $eyeColor}
  120.         Sphere $eyeRadius [expr {-$eyeRadius}] $eyeRadius 360 
  121.         ##########
  122.         startShape Pupil
  123.           set xTrans 0.0
  124.           set yTrans 0.0
  125.           set zTrans [expr {-$eyeRadius*.7}]
  126.           ApplyToCTM {Translate $xTrans $yTrans $zTrans}
  127.           EveCmd {Scale $pupilScale $pupilScale $pupilScale}
  128.           EveCmd {Color $pupilColor}
  129.           Sphere $pupilRadius [expr {-$pupilRadius}] $pupilRadius 360 
  130.         endShape ;#Pupil
  131.       endShape ;#EyeBall
  132.     endShape ;#LeftEye
  133.  
  134.     ##########
  135.     startShape RightEye
  136.       Surface plastic
  137.       EveCmd {Rotate $initialEyeYaw 1 0 0}
  138.       EveCmd {Rotate -$initialEyePitch 0 1 0}
  139.       EveCmd {Translate 0 \
  140.                         [expr {$headRadius*sin([dToR $initialEyeYaw])}] \
  141.                         [expr {-$eyeProtrusion*$headRadius*cos([dToR $initialEyeYaw])}]}
  142.       ##########
  143.       startShape EyeBall
  144.         EveCmd {Scale $eyeScale $eyeScale $eyeScale}
  145.         EveCmd {Rotate $eyeYaw 1 0 0}
  146.         EveCmd {Rotate $eyePitch 0 1 0}
  147.         EveCmd {Rotate $eyeRoll 0 0 1}
  148.         EveCmd {Color $eyeColor}
  149.         Sphere $eyeRadius [expr {-$eyeRadius}] $eyeRadius 360 
  150.         ##########
  151.         startShape Pupil
  152.           set xTrans 0.0
  153.           set yTrans 0.0
  154.           set zTrans [expr {-$eyeRadius*.7}]
  155.           ApplyToCTM {Translate $xTrans $yTrans $zTrans}
  156.           EveCmd {Scale $pupilScale $pupilScale $pupilScale}
  157.           EveCmd {Color $pupilColor}
  158.           Sphere $pupilRadius [expr {-$pupilRadius}] $pupilRadius 360 
  159.         endShape ;#Pupil
  160.       endShape ;#EyeBall
  161.     endShape ;#RightEye
  162.  
  163.     ##########
  164.     startShape Nose
  165.       set tenDegreesInRadians [dToR 10.0]
  166.       set xTrans 0.0
  167.       set yTrans [expr {$headRadius*sin($tenDegreesInRadians)}]
  168.       set zTrans [expr {.8*-$headRadius}]
  169.       ApplyToCTM {Translate $xTrans $yTrans $zTrans}
  170.       ApplyToCTM {Rotate 180.0 1 0 0}
  171.       EveCmd {Color $noseColor}
  172.       Cone $noseLength $noseWidth 360
  173.     endShape ;#Nose
  174.  
  175.     ##########
  176.     if {[string match martian* $kindOfHead]} { buildAntenna } {}
  177.     if {[string match punk* $kindOfHead]} { buildCrest } {}
  178.  
  179.   endShape ;#Head
  180. }
  181.  
  182.  
  183. proc buildCrest {} {
  184.   global crestCount crestLength crestWidth crestColor crestYawStep
  185.  
  186.   ##########
  187.   startShape Crest
  188.     EveCmd {Color $crestColor}
  189.     Rotate -110 1 0 0
  190.  
  191.     ##########
  192.     startShape LeftRow
  193.       ApplyToCTM {Rotate -30  0 0 1}
  194.       for {set i 0} {$i < $crestCount} {incr i} \
  195.       {  EveCmd {Cone $crestLength $crestWidth 360}
  196.          EveCmd {Rotate $crestYawStep 1 0 0}
  197.       }
  198.     endShape ;#LeftRow
  199.  
  200.     ##########
  201.     startShape MiddleRow
  202.       for {set i 0} {$i < $crestCount} {incr i} \
  203.       {  EveCmd {Cone $crestLength $crestWidth 360}
  204.          EveCmd {Rotate $crestYawStep 1 0 0}
  205.       }
  206.     endShape ;#MiddleRow
  207.  
  208.     ##########
  209.     startShape RightRow
  210.       ApplyToCTM {Rotate 30  0 0 1}
  211.       for {set i 0} {$i < $crestCount} {incr i} \
  212.       {  EveCmd {Cone $crestLength $crestWidth 360}
  213.          EveCmd {Rotate $crestYawStep 1 0 0}
  214.       }
  215.     endShape ;#RightRow
  216.   endShape ;#Crest
  217. }
  218.  
  219. proc buildAntenna {} {
  220.   global antennaColor antennaRadius antennaTilt antennaLength antennaKnobColor antennaKnobRadius 
  221.  
  222.  
  223.   startShape Antenna
  224.     EveCmd {Color $antennaColor}
  225.     ApplyToCTM {Rotate -90 1 0 0}
  226.  
  227.     ##########
  228.     startShape LeftShaft
  229.       EveCmd {Rotate -$antennaTilt  0 1 0}
  230.       EveCmd {Cylinder $antennaRadius 0 $antennaLength 360}
  231.  
  232.       ##########
  233.       startShape Knob
  234.         EveCmd {Color $antennaKnobColor}
  235.         EveCmd {Translate 0 0 $antennaLength}
  236.         EveCmd {Sphere $antennaKnobRadius -$antennaKnobRadius $antennaKnobRadius 360}
  237.       endShape ;#Knob 
  238.     endShape ;#LeftShaft
  239.  
  240.     ##########
  241.     startShape RightShaft
  242.       EveCmd {Rotate $antennaTilt  0 1 0}
  243.       EveCmd {Cylinder $antennaRadius 0 $antennaLength 360}
  244.  
  245.       ##########
  246.       startShape Knob
  247.         EveCmd {Color $antennaKnobColor}
  248.         EveCmd {Translate 0 0 $antennaLength}
  249.         EveCmd {Sphere $antennaKnobRadius -$antennaKnobRadius $antennaKnobRadius 360}
  250.       endShape ;#Knob 
  251.     endShape ;#LeftShaft
  252.   endShape ;#Antenna
  253. }
  254.  
  255. set kindOfTorso Blistered.5
  256. set torsoXScale 1
  257. set torsoYScale 1.55
  258. set torsoZScale 1
  259. set torsoRadius .4
  260. set torsoColor {.391522 .378109 1}
  261. set torsoSurfaceAge .5
  262.  
  263. proc buildSphereTorso {{xOrigin 0.0} {yOrigin 0.0} {zOrigin 0.0}} {
  264.   global torsoXScale torsoYScale torsoZScale
  265.   global torsoRadius torsoColor
  266.   global torsoSurfaceAge
  267.  
  268.  
  269.   Declare "Age" "float"
  270.   Declare "HeightScale" "float"
  271.   Declare "Gloss" "float"
  272.   Declare "Roughness" "float"
  273.   Declare "Displacement" "string"
  274.  
  275.   startShape Torso 
  276.     ApplyToCTM {Translate $xOrigin $yOrigin $zOrigin}
  277.     EveCmd {Color $torsoColor}
  278.     EveCmd {Scale $torsoXScale $torsoYScale $torsoZScale} 
  279.     # need to think about this... 
  280.     Surface VGBlisteredPaintedMetal Age $torsoSurfaceAge HeightScale 5 Gloss 1 Roughness 1 Displacement 1
  281.     EveCmd {Sphere $torsoRadius [expr {-$torsoRadius}] $torsoRadius 360 }
  282.   endShape ;#Torso
  283. }
  284.  
  285.  
  286. set armColor {.7 1 .7}
  287.  
  288. set shoulderRadius [expr 6.0*$headRadius/8.0]
  289. set upperArmRadius [expr $headRadius/2]
  290. set leftUpperArmRotate 0.0
  291. set rightUpperArmRotate 0.0
  292.  
  293. set elbowRadius [expr $shoulderRadius*.7]
  294. set foreArmRadius [expr $upperArmRadius*.8]
  295. set leftForeArmRotate 0.0
  296. set rightForeArmRotate 0.0
  297.  
  298.  
  299. proc buildSphereArm {{side Left} {xOrigin 0.0} {yOrigin 0.0} {zOrigin 0.0}} {
  300.   global shoulderRadius armColor
  301.   global upperArmRadius leftUpperArmRotate rightUpperArmRotate
  302.   global elbowRadius 
  303.   global foreArmRadius leftForeArmRotate rightForeArmRotate 
  304.  
  305.  
  306.   startShape ${side}Arm 
  307.     ApplyToCTM {Translate $xOrigin $yOrigin $zOrigin}
  308.     ApplyToCTM {Rotate 90 0 1 0}
  309.     ApplyToCTM {Rotate 90 1 0 0}
  310.     EveCmd {Color $armColor}
  311.  
  312.     ##########
  313.     startShape Shoulder
  314.       Sphere $shoulderRadius [expr {-$shoulderRadius}] $shoulderRadius 360 
  315.  
  316.       ##########
  317.       startShape UpperArm
  318.         set upperArmYScale 4.0
  319.         set upperArmLength [expr {$upperArmRadius*$upperArmYScale}]
  320.         set yTrans [expr {$upperArmLength + [expr {$shoulderRadius/2.0}]}]
  321.  
  322.         ApplyToCTM {Rotate 90 0 0 1}
  323.         if {[string compare Left $side]} \
  324.         {} \
  325.         {  set leftUpperArmRotate 45.0;
  326.            EveCmd {Rotate $leftUpperArmRotate 0 1 0}
  327.         }
  328.         if {[string compare Right $side]} \
  329.         {} \
  330.         {  set rightUpperArmRotate -45.0;
  331.            EveCmd {Rotate $rightUpperArmRotate 0 1 0}
  332.         }
  333.         set varName ${side}UpperArmRotate
  334.         
  335.         Cylinder $upperArmRadius 0 $upperArmLength 360
  336.  
  337.         ##########
  338.         startShape Elbow
  339.           ApplyToCTM {Translate 0 0 $upperArmLength}
  340.           Sphere $elbowRadius [expr {-$elbowRadius}] $elbowRadius 360 
  341.  
  342.           ##########
  343.           startShape foreArm
  344.             set foreArmLength [expr {$upperArmLength*1.2}]
  345.             set yTrans [expr {$foreArmLength + [expr {$elbowRadius/2.0}]}]
  346.  
  347.             if {[string compare Left $side]} \
  348.             {} \
  349.             {  set leftForeArmRotate -65.0;
  350.             EveCmd {Rotate $leftForeArmRotate 0 1 0}
  351.             }
  352.             if {[string compare Right $side]} \
  353.             {} \
  354.             {  set rightForeArmRotate 65.0;
  355.                EveCmd {Rotate $rightForeArmRotate 0 1 0}
  356.             }
  357.             Cylinder $foreArmRadius 0 $foreArmLength 360
  358.           endShape ;# foreArm
  359.         endShape ;# Elbow
  360.       endShape ;#UpperArm
  361.     endShape ;#Shoulder
  362.   endShape ;#Arm
  363. }
  364.  
  365. proc buildRobot {} {
  366.   global kindOfHead headRadius initialEyePitch eyeScale antennaRadius antennaLength
  367.   global kindOfTorso torsoRadius torsoYScale torsoSurfaceAge
  368.  
  369.  
  370.   if {[string compare $kindOfHead fish]} \
  371.   {} \
  372.   { set initialEyePitch 45; 
  373.     set eyeScale 2; 
  374.   }
  375.  
  376.   if {[string compare $kindOfHead insect]} \
  377.   {} \
  378.   { set initialEyePitch 80; 
  379.     set eyeScale 3; 
  380.   }
  381.  
  382.   if {[string compare $kindOfHead martianFish]} \
  383.   {} \
  384.   { set initialEyePitch 45; 
  385.     set eyeScale 2; 
  386.   }
  387.  
  388.   if {[string compare $kindOfHead martianInsect]} \
  389.   {} \
  390.   { set initialEyePitch 80; 
  391.     set eyeScale 3; 
  392.     set antennaRadius 0.01; 
  393.     set antennaLength 0.7; 
  394.   }
  395.  
  396.   if {[string compare $kindOfHead punkFish]} \
  397.   {} \
  398.   { set initialEyePitch 45; 
  399.     set eyeScale 2; 
  400.   }
  401.  
  402.   if {[string compare $kindOfHead punkInsect]} \
  403.   {} \
  404.   { set initialEyePitch 80; 
  405.     set eyeScale 3; 
  406.   }
  407.  
  408.   if {[string compare $kindOfTorso Blistered.1]} \
  409.   {} \
  410.   { set torsoSurfaceAge .1
  411.   }
  412.   if {[string compare $kindOfTorso Blistered.2]} \
  413.   {} \
  414.   { set torsoSurfaceAge .2
  415.   }
  416.   if {[string compare $kindOfTorso Blistered.3]} \
  417.   {} \
  418.   { set torsoSurfaceAge .3
  419.   }
  420.   if {[string compare $kindOfTorso Blistered.4]} \
  421.   {} \
  422.   { set torsoSurfaceAge .4
  423.   }
  424.   if {[string compare $kindOfTorso Blistered.5]} \
  425.   {} \
  426.   { set torsoSurfaceAge .5
  427.   }
  428.   if {[string compare $kindOfTorso Blistered.5]} \
  429.   {} \
  430.   { set torsoSurfaceAge .5
  431.   }
  432.   if {[string compare $kindOfTorso Blistered.6]} \
  433.   {} \
  434.   { set torsoSurfaceAge .6
  435.   }
  436.   if {[string compare $kindOfTorso Blistered.7]} \
  437.   {} \
  438.   { set torsoSurfaceAge .7
  439.   }
  440.   if {[string compare $kindOfTorso Blistered.8]} \
  441.   {} \
  442.   { set torsoSurfaceAge .8
  443.   }
  444.  
  445.   startRootShape Robot
  446.     declareShaderAttributes
  447.     buildSphereTorso
  448.     buildSphereHead 0 [expr {1.2 * $headRadius + [expr {$torsoRadius * $torsoYScale}]}] 0
  449.     buildSphereArm Left [expr {$torsoRadius * .9}] [expr {.7 * $torsoRadius * $torsoYScale}] 0
  450.     buildSphereArm Right -[expr {$torsoRadius * .9}] [expr {.7 * $torsoRadius * $torsoYScale}] 0
  451.   endShape
  452.  
  453.   installRootShape
  454. }
  455.  
  456. proc nod {{howManySteps 4} {nodIncrement 10}} {
  457.   global nodAngle
  458.  
  459.  
  460.   # lift up a bit, then nod twice, then settle back to original angle
  461.   set nodAngle [expr {$nodAngle+$nodIncrement}]; updateView
  462.   for {set i 0} {$i < $howManySteps} {incr i} {set nodAngle [expr {$nodAngle-$nodIncrement}]; updateView}
  463.   for {set i 0} {$i < $howManySteps} {incr i} {set nodAngle [expr {$nodAngle+$nodIncrement}]; updateView}
  464.   for {set i 0} {$i < $howManySteps} {incr i} {set nodAngle [expr {$nodAngle-$nodIncrement}]; updateView}
  465.   for {set i 0} {$i < $howManySteps} {incr i} {set nodAngle [expr {$nodAngle+$nodIncrement}]; updateView}
  466.   set nodAngle [expr {$nodAngle-$nodIncrement}]; updateView
  467. }
  468.  
  469. proc shake {{howManySteps 4} {shakeIncrement 10}} {
  470.   global shakeAngle
  471.  
  472.  
  473.   for {set i 0} {$i < $howManySteps} {incr i} {set shakeAngle [expr {$shakeAngle+$shakeIncrement}]; updateView}
  474.   for {set i 0} {$i < $howManySteps} {incr i} {set shakeAngle [expr {$shakeAngle-$shakeIncrement}]; updateView}
  475.   for {set i 0} {$i < $howManySteps} {incr i} {set shakeAngle [expr {$shakeAngle+$shakeIncrement}]; updateView}
  476.   for {set i 0} {$i < $howManySteps} {incr i} {set shakeAngle [expr {$shakeAngle-$shakeIncrement}]; updateView}
  477. }
  478.  
  479. buildRobot
  480.  
  481.